package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.utils.AliOSSUtils;
import com.itheima.advantagesup.vo.FileVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: youdian-da
 * @className: UploadController
 * @description: TODO
 * @author: xch
 * @createTime: 2023-07-26 20:29
 **/
@RequestMapping("/common/upload")
@RestController
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping
    public R<?> upload(@RequestBody MultipartFile file, String type) throws Exception {
        String url = aliOSSUtils.upload(file);
        FileVO fileVO = new FileVO(url,AliOSSUtils.fileName,type,(int) file.getSize());
        return R.success(fileVO);
    }
}
